import { ApiProperty } from "@nestjs/swagger";
import { IsDefined, IsOptional, Length } from "class-validator";
import {IsFile} from "~/modules/tools/upload/file.constraint";
import {MultipartFile} from "@fastify/multipart";

export class BookCreateDto {
	@ApiProperty({type: 'string', format: 'binary', description: '文件'})
  @IsDefined()
  @IsFile(
    {
      mimetypes: [
        'image/png',
        'image/jpg',
        'image/jpeg',
      ],
      fileSize: 1024 * 1024 * 3,
    },
    {
      message: '文件类型不正确',
    },
  )
  file: MultipartFile

	// 书名和简介
	@ApiProperty({description: '书名', type: String})
	@IsDefined()
	@Length(1, 10, { message: '书名长度必须在1到10个字符之间' })
	name: string

	@ApiProperty({description: '作者', type: String})
	@Length(1, 50, { message: '作者长度必须在1到10个字符之间' })
	authors: string

	@ApiProperty({description: '简介', type: String, required: false})
	@IsOptional()
	@Length(1, 500, { message: '简介长度必须在1到500个字符之间' })
	introduction: string
}

export class BookDelDto {
	@ApiProperty({description: '书籍id', type: Number})
	@IsDefined()
	id: number
}

export class CatalogCreateDto {
	@ApiProperty({description: '目录', type: String})
	@IsDefined()
	@Length(1, 50, { message: '目录长度必须在1到50个字符之间' })
	name: string

	@ApiProperty({description: '书籍id', type: Number})
	@IsDefined()
	bookId: number

	@ApiProperty({description: '内容', type: String})
	@IsDefined()
	content: string
}

export class CatalogUpdateDto {
	@ApiProperty({description: '目录id', type: Number})
	@IsDefined()
	id: number

	@ApiProperty({description: '目录', type: String})
	@IsDefined()
	@Length(1, 50, { message: '目录长度必须在1到50个字符之间' })
	name: string

	@ApiProperty({description: '内容', type: String})
	@IsDefined()
	content: string
}

export class CatalogDelDto {
	@ApiProperty({description: '目录id', type: Number})
	@IsDefined()
	id: number
}